package com.xavier.dong.nacos.grpc.client.config;

import com.xavier.dong.nacos.grpc.client.interceptor.LogGrpcInterceptor;
import io.grpc.CallCredentials;
import io.grpc.ClientInterceptor;
import net.devh.boot.grpc.client.interceptor.GrpcGlobalClientInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * Example configuration class that adds a {@link ClientInterceptor} to the global interceptor list.
 */
//@Order(Ordered.LOWEST_PRECEDENCE)
@Configuration(proxyBeanMethods = false)
public class GlobalInterceptorConfiguration {

    @Value("${auth.username}")
    private String username;

    /**
     * Creates a new {@link LogGrpcInterceptor} bean and adds it to the global interceptor list. As an alternative you
     * can directly annotate the {@code LogGrpcInterceptor} class and it will automatically be picked up by spring's
     * classpath scanning.
     *
     * @return The newly created bean.
     */
    @GrpcGlobalClientInterceptor
    LogGrpcInterceptor logClientInterceptor() {
        return new LogGrpcInterceptor();
    }

    /**
     * grpc凭证
     * <p>
     * Create credentials for username + password.
     *
     * @return {@link CallCredentials}
     */
    //@Bean
    //CallCredentials grpcCredentials() {
    //    return CallCredentialsHelper.basicAuth(this.username, this.username + "Password");
    //}

}